package com.xs.ahoi.hcxs.ui.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.xs.ahoi.hcxs.R;

/**
 * 导入页面长按目录弹出加入收藏
 */
public class DialogCollectPath extends BaseBubbleDialog implements View.OnClickListener {

    @BindView(R.id.tvAddCollect)
    public TextView tvAddCollect;
    // 是否显示加入收藏
    private boolean isAdd;

    // 点击事件监听
    private Listener mListener;

    @Override
    public View getLayout() {
        return LayoutInflater.from(getContext()).inflate(R.layout.dialog_collect_path, null);
    }

    public DialogCollectPath(Context context) {
        super(context);
        calBar(true);
        nearToClickItem();
    }

    @OnClick({R.id.tvAddCollect})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tvAddCollect:
                if (isAdd) {
                    mListener.add();
                } else {
                    mListener.remove();
                }
                break;
        }
    }

    // 显示在上方
    public void setTop() {
        setPosition(Position.TOP);
    }

    // 显示在下方
    public void setBottom() {
        setPosition(Position.BOTTOM);
    }

    public DialogCollectPath showText(boolean isAdd) {
        this.isAdd = isAdd;
        if (isAdd) {
            showAdd();
        } else {
            showRemove();
        }
        return this;
    }

    // 显示加入收藏
    public void showAdd() {
        tvAddCollect.setText(getContext().getString(R.string.collect_path_add));
        isAdd = true;
    }

    // 显示取消收藏
    public void showRemove() {
        tvAddCollect.setText(getContext().getString(R.string.collect_path_remove));
        isAdd = false;
    }


    public void setClickListener(Listener l) {
        this.mListener = l;
    }

    public interface Listener {
        void add();

        void remove();
    }
}